package com.hj.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hj.dao.TeacherMapper;
import com.hj.pojo.Teacher;
import com.hj.pojo.TeacherExample;
import com.hj.pojo.TeacherExample.Criteria;
import com.hj.service.ITeacherService;

@Service
public class TeacherServiceImpl implements ITeacherService {

	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
	
	@Autowired
	TeacherMapper teacherMapper;
	
	@Override
	public PageInfo<Teacher> list(Integer page, Integer size, Teacher teacher) {
		// TODO Auto-generated method stub
		PageHelper.startPage(page, size);
		TeacherExample ex = new TeacherExample();
		Criteria criteria = ex.createCriteria();
		if (!StringUtils.isEmpty(teacher.gettName())) {
			criteria.andTNameLike("%"+ teacher.gettName() +"%");
		}
		
		List<Teacher> list = teacherMapper.selectByExample(ex);
		PageInfo<Teacher> pageInfo = new PageInfo<>(list);
		return pageInfo;
	}

	@Override
	public void add(Teacher teacher) {
		// TODO Auto-generated method stub
		teacher.settId(sdf.format(new Date()));
		teacherMapper.insertSelective(teacher);
	}

	@Override
	public void delete(String id) {
		// TODO Auto-generated method stub
		teacherMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void update(Teacher teacher) {
		// TODO Auto-generated method stub
		teacherMapper.updateByPrimaryKeySelective(teacher);
	}

	@Override
	public Teacher findOne(String id) {
		// TODO Auto-generated method stub
		return teacherMapper.selectByPrimaryKey(id);
	}

}
